using DiLu.Expansion.File.Configs;
using FluentFTP;

namespace DiLu.Expansion.File.Operates.FTP.Configs;

/// <summary>
///     FTP文件搜索配置
/// </summary>
public record SearchFtpFileConfig : SearchFileConfig
{
    /// <summary>
    ///     FTP文件搜索配置
    /// </summary>
    /// <param name="directoryFullPath">目录完整路径</param>
    /// <param name="ftpClient">FTP客户端</param>
    /// <param name="autoCloseFtpClient">
    ///     自动关闭FTP客户端 默认自动关闭客户端连接
    ///     如果为false需要自行调用 CloseFtpClientConnectAsync()方法
    /// </param>
    /// <param name="searchOption">搜索选项</param>
    /// <param name="searchPattern">
    ///     模糊查询模式，默认匹配所有文件
    ///     如果想查询指定类型文件使用 ^([\s\S]+)(\.(jpg|png))$
    ///     如果想模糊查询文件使用  ^([\s\S]*)name([\s\S]*)(\.\w+)$
    /// </param>
    public SearchFtpFileConfig(string directoryFullPath, AsyncFtpClient ftpClient, bool autoCloseFtpClient,
        SearchOption searchOption = SearchOption.TopDirectoryOnly,
        string searchPattern = @"^([\s\S]+)(\.\w+)?$")
        : base(directoryFullPath, searchOption, searchPattern)
    {
        ArgumentNullException.ThrowIfNull(ftpClient, nameof(ftpClient));
        FtpClient = ftpClient;
        AutoCloseFtpClient = autoCloseFtpClient;
    }

    /// <summary>
    ///     FTP文件搜索配置
    /// </summary>
    /// <param name="rootDirectory">根目录</param>
    /// <param name="fileGroupName">文件分组名称</param>
    /// <param name="directoryRelativePath">目录相对路径</param>
    /// <param name="ftpClient">FTP客户端</param>
    /// <param name="autoCloseFtpClient">
    ///     自动关闭FTP客户端 默认自动关闭客户端连接
    ///     如果为false需要自行调用 CloseFtpClientConnectAsync()方法
    /// </param>
    /// <param name="searchOption">搜索选项</param>
    /// <param name="searchPattern">
    ///     模糊查询模式，默认匹配所有文件
    ///     如果想查询指定类型文件使用 ^([\s\S]+)(\.(jpg|png))$
    ///     如果想模糊查询文件使用  ^([\s\S]*)name([\s\S]*)(\.\w+)$
    /// </param>
    public SearchFtpFileConfig(string rootDirectory, string fileGroupName, string directoryRelativePath,
        AsyncFtpClient ftpClient, bool autoCloseFtpClient,
        SearchOption searchOption = SearchOption.TopDirectoryOnly,
        string searchPattern = @"^([\s\S]+)(\.\w+)?$")
        : base(rootDirectory, fileGroupName, directoryRelativePath, searchOption, searchPattern)
    {
        ArgumentNullException.ThrowIfNull(ftpClient, nameof(ftpClient));
        FtpClient = ftpClient;
        AutoCloseFtpClient = autoCloseFtpClient;
    }

    /// <summary>
    ///     FTP客户端
    /// </summary>
    public AsyncFtpClient FtpClient { get; }

    /// <summary>
    ///     自动关闭FTP客户端
    /// </summary>
    public bool AutoCloseFtpClient { get; }
}